package fr.upmc.cie.data.dbaccess;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DBOpenHelper extends SQLiteOpenHelper{

	public DBOpenHelper(Context context, String name, int version) {
		super(context, name, null, version);
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		db.execSQL("CREATE TABLE ticket (id_ticket INTEGER PRIMARY KEY,"+
				"title TEXT , source TEXT , date TEXT, author TEXT ,"+
				"link TEXT , content TEXT , isReaded NUMERIC , rating NUMERIC);");
		db.execSQL("CREATE TABLE categorie (id_categorie INTEGER PRIMARY KEY, name TEXT);");
		db.execSQL("CREATE TABLE channel (id_channel INTEGER PRIMARY KEY, title TEXT, URL TEXT);");
		db.execSQL("CREATE TABLE categorie_channel (id INTEGER PRIMARY KEY, id_categorie INTEGER, id_channel INTEGER);");
		db.execSQL("INSERT INTO categorie (name) values ('Sport')");
		db.execSQL("INSERT INTO categorie (name) values ('News')");
		db.execSQL("INSERT INTO categorie (name) values ('Technology')");
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		db.execSQL("DROP TABLE IF EXISTS ticket");
		db.execSQL("DROP TABLE IF EXISTS categorie");
		db.execSQL("DROP TABLE IF EXISTS channel");
		db.execSQL("DROP TABLE IF EXISTS categorie_channel");
		onCreate(db);
	}
	
}
